#!/bin/bash

#стол сущ.м/сущ.ж/сущ.ср/прил/числ/мест/гл.с/гл.нс/нар
#стол SM|SW|SN|PR|CH|ME|GS|GN|NA
TRUE=1
FALSE=0

CHASTI="chasti_rechi.txt"
FORMY="formy_slov.txt"
SLOVA="slova.txt"
OUT="out.tmp"

SM='м\.'
SW='ж\.'
SN='ср\.'
SA='мн\.'
PR='прил\.'
CH='числит\.'
ME='местоим\.'
GS='сов\.'
GN='несов\.'
NA='нареч\.'
#IM - imya sobstven
#X - slovlo est, no neizvestanya chast rechi
#- - net slova in FORMY
#rm -f $OUT

i=28893
while [ 1 -eq 1 ];do
#	sl="`sed -n "$i p" $SLOVA`"
	echo -n "$i "
	line="`sed -n "$i p" $FORMY`"
#	echo "line=$line"
	sl="`echo "$line" |cut -d " " -f 1`"
	sltail="`echo "$line" | sed -e "s/^$s //"`"
	if [ "$sl" = "" ];then
		break
	fi	
	echo "$sl"|grep -E -q "^[АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧЪЫЬЭЮЯ]"
	if [ $? -eq 0 ];then
		chast="IM"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi

	ch="`grep -E -A 2 "^$sl$" $CHASTI | tail -n 2`"
#	echo "ch=$ch"
	if [ "$ch" = "" ];then
		echo "$sl - $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" |sed -n "1 p"|grep -q "I"
	if [ $? -eq 0 ];then
		ch="`echo "$ch" |sed -n "2 p"`"
	else
		ch="`echo "$ch" |sed -n "1 p"`"
	fi
	echo "$ch" | grep -q " $SM"
	if [ $? -eq 0 ];then
		chast="SM"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $SW"
	if [ $? -eq 0 ];then
		chast="SW"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $SN"
	if [ $? -eq 0 ];then
		chast="SN"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $SA"
	if [ $? -eq 0 ];then
		chast="SA"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi

	echo "$ch" | grep -q " $PR"
	if [ $? -eq 0 ];then
		chast="PR"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi

	echo "$ch" | grep -q " $CH"
	if [ $? -eq 0 ];then
		chast="CH"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $ME"
	if [ $? -eq 0 ];then
		chast="ME"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi

	echo "$ch" | grep -q " $GS"
	if [ $? -eq 0 ];then
		chast="GS"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $NA"
	if [ $? -eq 0 ];then
		chast="NA"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi
	echo "$ch" | grep -q " $GN"
	if [ $? -eq 0 ];then
		chast="GN"
		echo "$sl $chast $sltail" >> $OUT
		i=`expr $i + 1`
		continue
	fi

	echo "$sl X $sltail" >> $OUT
	i=`expr $i + 1`
done
